<?php 
require_once("admin-header.php");
require_once("../include/check_get_key.php");
$cid=intval($_GET['cid']);
$bm_c_id=$cid;
$oper=intval($_GET['oper']);
if(!(isset($_SESSION["m$cid"])||isset($_SESSION[$BM_ADMIN])||isset($_SESSION['administrator']))) exit();
if($oper==0)
{
	$bm_t_ojid=$_GET['ojid'];
	$bm_t_id=$_GET['tid'];
	$sql="SELECT * FROM `bm_team` WHERE `bm_c_id`=$bm_c_id AND `bm_t_ojid`='$bm_t_ojid' AND `bm_t_id`='$bm_t_id'";
	$result=mysql_query($sql);
	$num=mysql_num_rows($result);
	if ($num<1)
	{
		mysql_free_result($result);
		echo "No Such Team!";
		require_once("../bm-footer.php");
		exit(0);
	}
	$row=mysql_fetch_assoc($result);
	$bm_t_id=$row['bm_t_id'];
	mysql_free_result($result);
	$sql="DELETE FROM `bm_stu` WHERE `bm_t_id`=$bm_t_id";
	mysql_query($sql) or die(mysql_error());
	$sql="DELETE FROM `bm_team` WHERE `bm_t_id`=$bm_t_id";
	mysql_query($sql) or die(mysql_error());
	mysql_free_result($result);
}
else
{
	$sql="SELECT * FROM `bm_contest` WHERE `bm_c_id`=$bm_c_id";
	$result=mysql_query($sql);
	$num=mysql_num_rows($result);
	if ($num<1)
	{
		mysql_free_result($result);
		echo "No Such Contest!";
		require_once("../bm-footer.php");
		exit(0);
	}
	$sql="DELETE FROM `bm_contest` WHERE `bm_c_id`=$bm_c_id";
	mysql_query($sql) or die(mysql_error());
	mysql_free_result($result);
	$sql="SELECT * FROM `bm_team` WHERE `bm_c_id`=$bm_c_id";
	$result=mysql_query($sql);
	while($row = mysql_fetch_array($result))
	{
		$bm_t_id=$row['bm_t_id'];
		$sql="DELETE FROM `bm_stu` WHERE `bm_t_id`=$bm_t_id";
		mysql_query($sql) or die(mysql_error());
		$sql="DELETE FROM `bm_team` WHERE `bm_t_id`=$bm_t_id";
		mysql_query($sql) or die(mysql_error());
	}
	mysql_free_result($result);
}
	
?>
<script language=javascript>
	history.go(-1);
</script>

